using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using MobileClient.UIProcessService;

namespace MobileClient
{
	/// <summary>
	/// Summary description for ctlPhoneEntryNA.
	/// </summary>
	public class ctlPhoneEntryNA : Control
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.TabControl tabControl;
		private System.Windows.Forms.TabPage tabCountry;
		private System.Windows.Forms.TextBox txtCountryCode;
		private System.Windows.Forms.TabPage tabNational;
		private System.Windows.Forms.TextBox txtNational;
		private System.Windows.Forms.TabPage tabArea;
		private System.Windows.Forms.TextBox txtAreaCode;
		private System.Windows.Forms.TabPage tabNumber;
		private System.Windows.Forms.TextBox txtNumber;
		private System.Windows.Forms.TabPage tabExtension;
		private System.Windows.Forms.TextBox txtExtension;
		private System.Windows.Forms.TabPage tabPIN;
		private System.Windows.Forms.TextBox txtPIN;
		private System.Windows.Forms.TabPage tabNA;
		private System.Windows.Forms.CheckBox chkNA;
		private PhoneEntryNA m_objEntry;
		private int m_nSelected = 0;
		private Microsoft.WindowsCE.Forms.InputPanel pnlSIP;

		public ctlPhoneEntryNA()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			m_objEntry = null;
			pnlSIP = null;
		}

		public PhoneEntryNA Entry
		{
			get { return m_objEntry; }
			set { m_objEntry = value; }
		}

		public Microsoft.WindowsCE.Forms.InputPanel SIPPanel
		{
			get { return pnlSIP; }
			set { pnlSIP = value; }
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if( components != null )
					components.Dispose();
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.tabControl = new System.Windows.Forms.TabControl();
			this.tabCountry = new System.Windows.Forms.TabPage();
			this.txtCountryCode = new System.Windows.Forms.TextBox();
			this.tabNational = new System.Windows.Forms.TabPage();
			this.txtNational = new System.Windows.Forms.TextBox();
			this.tabArea = new System.Windows.Forms.TabPage();
			this.txtAreaCode = new System.Windows.Forms.TextBox();
			this.tabNumber = new System.Windows.Forms.TabPage();
			this.txtNumber = new System.Windows.Forms.TextBox();
			this.tabExtension = new System.Windows.Forms.TabPage();
			this.txtExtension = new System.Windows.Forms.TextBox();
			this.tabPIN = new System.Windows.Forms.TabPage();
			this.txtPIN = new System.Windows.Forms.TextBox();
			this.tabNA = new System.Windows.Forms.TabPage();
			this.chkNA = new System.Windows.Forms.CheckBox();
			// 
			// tabControl
			// 
			this.tabControl.Controls.Add(this.tabCountry);
			this.tabControl.Controls.Add(this.tabArea);
			this.tabControl.Controls.Add(this.tabExtension);
			this.tabControl.Controls.Add(this.tabNA);
			this.tabControl.Controls.Add(this.tabNational);
			this.tabControl.Controls.Add(this.tabNumber);
			this.tabControl.Controls.Add(this.tabPIN);
			this.tabControl.Location = new System.Drawing.Point(3, 6);
			this.tabControl.SelectedIndex = 0;
			this.tabControl.Size = new System.Drawing.Size(230, 140);
			this.tabControl.SelectedIndexChanged +=new EventHandler(tabControl_SelectedIndexChanged);
			// 
			// tabCountry
			// 
			this.tabCountry.Controls.Add(this.txtCountryCode);
			this.tabCountry.Location = new System.Drawing.Point(4, 22);
			this.tabCountry.Size = new System.Drawing.Size(222, 114);
			this.tabCountry.Text = "Country";
			// 
			// txtCountryCode
			// 
			this.txtCountryCode.Location = new System.Drawing.Point(5, 47);
			this.txtCountryCode.Size = new System.Drawing.Size(212, 20);
			this.txtCountryCode.Text = "";
			this.txtCountryCode.GotFocus += new EventHandler(txtCountryCode_GotFocus);
			// 
			// tabNational
			// 
			this.tabNational.Controls.Add(this.txtNational);
			this.tabNational.Location = new System.Drawing.Point(4, 22);
			this.tabNational.Size = new System.Drawing.Size(222, 114);
			this.tabNational.Text = "National";
			this.tabNational.Visible = false;
			// 
			// txtNational
			// 
			this.txtNational.Location = new System.Drawing.Point(5, 47);
			this.txtNational.Size = new System.Drawing.Size(212, 20);
			this.txtNational.Text = "";
			this.txtNational.GotFocus += new EventHandler(txtNational_GotFocus);
			// 
			// tabArea
			// 
			this.tabArea.Controls.Add(this.txtAreaCode);
			this.tabArea.Location = new System.Drawing.Point(4, 22);
			this.tabArea.Size = new System.Drawing.Size(222, 114);
			this.tabArea.Text = "Area";
			this.tabArea.Visible = false;
			// 
			// txtAreaCode
			// 
			this.txtAreaCode.Location = new System.Drawing.Point(5, 47);
			this.txtAreaCode.Size = new System.Drawing.Size(212, 20);
			this.txtAreaCode.Text = "";
			this.txtAreaCode.GotFocus += new EventHandler(txtAreaCode_GotFocus);
			// 
			// tabNumber
			// 
			this.tabNumber.Controls.Add(this.txtNumber);
			this.tabNumber.Location = new System.Drawing.Point(4, 22);
			this.tabNumber.Size = new System.Drawing.Size(222, 114);
			this.tabNumber.Text = "Number";
			this.tabNumber.Visible = false;
			// 
			// txtNumber
			// 
			this.txtNumber.Location = new System.Drawing.Point(5, 47);
			this.txtNumber.Size = new System.Drawing.Size(212, 20);
			this.txtNumber.Text = "";
			this.txtNumber.GotFocus += new EventHandler(txtNumber_GotFocus);
			// 
			// tabExtension
			// 
			this.tabExtension.Controls.Add(this.txtExtension);
			this.tabExtension.Location = new System.Drawing.Point(4, 22);
			this.tabExtension.Size = new System.Drawing.Size(222, 114);
			this.tabExtension.Text = "Ext.";
			this.tabExtension.Visible = false;
			// 
			// txtExtension
			// 
			this.txtExtension.Location = new System.Drawing.Point(5, 47);
			this.txtExtension.Size = new System.Drawing.Size(212, 20);
			this.txtExtension.Text = "";
			this.txtExtension.GotFocus += new EventHandler(txtExtension_GotFocus);
			// 
			// tabPIN
			// 
			this.tabPIN.Controls.Add(this.txtPIN);
			this.tabPIN.Location = new System.Drawing.Point(4, 22);
			this.tabPIN.Size = new System.Drawing.Size(222, 114);
			this.tabPIN.Text = "P.I.N.";
			this.tabPIN.Visible = false;
			// 
			// txtPIN
			// 
			this.txtPIN.Location = new System.Drawing.Point(5, 47);
			this.txtPIN.Size = new System.Drawing.Size(212, 20);
			this.txtPIN.Text = "";
			this.txtPIN.GotFocus += new EventHandler(txtPIN_GotFocus);
			// 
			// tabNA
			// 
			this.tabNA.Controls.Add(this.chkNA);
			this.tabNA.Location = new System.Drawing.Point(4, 22);
			this.tabNA.Size = new System.Drawing.Size(222, 114);
			this.tabNA.Text = "N/A";
			// 
			// chkNA
			// 
			this.chkNA.Location = new System.Drawing.Point(59, 45);
			this.chkNA.Text = "Not Applicable";
			// 
			// ctlPhoneEntryNA
			// 
			this.Controls.Add(this.tabControl);
			this.Size = new System.Drawing.Size(236, 152);

		}
		#endregion

		public void LoadSettings()
		{
			tabControl.SelectedIndex = 0;

			if(m_objEntry != null)
			{
				tabControl.SelectedIndex = 0;

                if (!String.IsNullOrEmpty(m_objEntry.CountryCode))
                {
                    txtCountryCode.Text = m_objEntry.CountryCode;
                }
                else
                {
                    txtCountryCode.Text = "";
                }

                if (!String.IsNullOrEmpty(m_objEntry.NationalCode))
                {
                    txtNational.Text = m_objEntry.NationalCode;
                }
                else
                {
                    txtNational.Text = "";
                }

                if (!String.IsNullOrEmpty(m_objEntry.AreaCode))
                {
                    txtAreaCode.Text = m_objEntry.AreaCode;
                }
                else
                {
                    txtAreaCode.Text = "";
                }

                if (!String.IsNullOrEmpty(m_objEntry.Number))
                {
                    txtNumber.Text = m_objEntry.Number;
                }
                else
                {
                    txtNumber.Text = "";
                }

                if (!String.IsNullOrEmpty(m_objEntry.Extension))
                {
                    txtExtension.Text = m_objEntry.Extension;
                }
                else
                {
                    txtExtension.Text = "";
                }

                if (!String.IsNullOrEmpty(m_objEntry.Pin))
                {
                    txtPIN.Text = m_objEntry.Pin;
                }
                else
                {
                    txtPIN.Text = "";
                }
                
                chkNA.Checked = m_objEntry.NotApplicable;
			}
		}

		public void SaveSettings()
		{
			if(m_objEntry != null)
			{
				m_objEntry.CountryCode= txtCountryCode.Text;
				m_objEntry.NationalCode = txtNational.Text;
				m_objEntry.AreaCode = txtAreaCode.Text;
				m_objEntry.Number = txtNumber.Text;
				m_objEntry.Extension = txtExtension.Text;
				m_objEntry.Pin = txtPIN.Text;
				m_objEntry.NotApplicable = chkNA.Checked;
			}
		}

		private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
		{
			int nIndex = tabControl.SelectedIndex;
			tabControl.TabPages[m_nSelected].Visible = false;			
			tabControl.TabPages[nIndex].Visible = true;
			m_nSelected = nIndex;
		}
		private void txtCountryCode_GotFocus(object sender, EventArgs e)
		{
			pnlSIP.Enabled = true;
		}

		private void txtNational_GotFocus(object sender, EventArgs e)
		{
			pnlSIP.Enabled = true;
		}

		private void txtAreaCode_GotFocus(object sender, EventArgs e)
		{
			pnlSIP.Enabled = true;
		}

		private void txtNumber_GotFocus(object sender, EventArgs e)
		{
			pnlSIP.Enabled = true;
		}

		private void txtExtension_GotFocus(object sender, EventArgs e)
		{
			pnlSIP.Enabled = true;
		}

		private void txtPIN_GotFocus(object sender, EventArgs e)
		{
			pnlSIP.Enabled = true;
		}
	}
}
